package com.hdjk.view.activity.personalcenter;

import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hdjk.view.R;
import com.hdjk.view.callback.CallBackListener;
import com.hdjk.view.entity.RiskTestReturnEntity;
import com.hdjk.view.network.Network;
import com.hdjk.view.util.UserTokenUtil;
import com.lst.projectlib.base.BaseActivity;
import com.lst.projectlib.entity.Msg;

/**
 * Created by sxy on 2017/11/15.
 */

public class RiskTestReturnActivity extends BaseActivity implements View.OnClickListener {
    private RiskTestReturnEntity mEntity;
    // Content View Elements
    private com.lst.projectlib.component.CustomView.TopTitleBar ttb_title_bar;
    private ImageView iv_top;
    private TextView tv_title;
    private TextView tv_point;
    private Button btn_reset;
    // End Of Content View Elements

    private void bindViews() {
        ttb_title_bar = (com.lst.projectlib.component.CustomView.TopTitleBar) findViewById(R.id.ttb_title_bar);
        iv_top = (ImageView) findViewById(R.id.iv_top);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_point = (TextView) findViewById(R.id.tv_point);
        btn_reset = (Button) findViewById(R.id.btn_reset);
    }


    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_risk_test_return);
        bindViews();
        ttb_title_bar.findViewById(R.id.tvNavBack).setOnClickListener(this);
        btn_reset.setOnClickListener(this);
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        ViewGroup.LayoutParams layoutParams=iv_top.getLayoutParams();
        layoutParams.width=dm.widthPixels;
        layoutParams.height=(int)((float)(dm.widthPixels)/1080*390);
        iv_top.setLayoutParams(layoutParams);
    }

    @Override
    protected void initData() {
        int type = getIntent().getIntExtra("type", 0);
        if (type == 1) {
            Network.getRiskTestDesc(UserTokenUtil.getToken(this), getIntent().getStringExtra("risk"), new CallBackListener() {
                @Override
                public void onCallBackCompleted(Msg msg) {
                    if (msg != null && msg.getSuccess() && msg.getData() != null && msg.getData() instanceof RiskTestReturnEntity) {
                        mEntity = (RiskTestReturnEntity) msg.getData();
                        setViews();
                    }
                }

                @Override
                public void onCallBackError(Msg msg) {

                }
            });
        } else if (type == 2) {
            mEntity = (RiskTestReturnEntity) getIntent().getExtras().getSerializable("entity");
            setViews();
        }

    }

    private void setViews() {
        if (mEntity != null) {
            tv_title.setText(mEntity.getTitle());
            tv_point.setText(mEntity.getPoint());
            switch (mEntity.getRiskRating()) {
                case "1":
                    iv_top.setImageDrawable(getResources().getDrawable(R.drawable.risk_1));
                    break;
                case "2":
                    iv_top.setImageDrawable(getResources().getDrawable(R.drawable.risk_2));
                    break;
                case "3":
                    iv_top.setImageDrawable(getResources().getDrawable(R.drawable.risk_3));
                    break;
                case "4":
                    iv_top.setImageDrawable(getResources().getDrawable(R.drawable.risk_4));
                    break;
                case "5":
                    iv_top.setImageDrawable(getResources().getDrawable(R.drawable.risk_5));
                    break;
            }
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvNavBack:
                back();
                break;
            case R.id.btn_reset:
                Intent intent = new Intent(RiskTestReturnActivity.this, RiskTestListActivity.class);
                startActivity(intent);
                back();
                break;
        }
    }
}
